# -*- coding: utf-8 -*-
__author__ = 'benxing'

import json
import datetime
from decimal import Decimal

class MyJsonEncoder(json.JSONEncoder):
    def default(self, obj):
        # if isinstance(obj, datetime.datetime):
        #     return int(mktime(obj.timetuple()))
        if isinstance(obj, datetime.datetime):
            return obj.strftime('%Y-%m-%d %H:%M:%S')
        elif isinstance(obj, datetime.date):
            return obj.strftime('%Y-%m-%d')
        elif isinstance(obj,float):
            return obj.__float__()
        elif isinstance(obj,Decimal):
            return obj.__float__()
        else:
            return json.JSONEncoder.default(self, obj)

if __name__ == "__main__":
    print json.dumps(
        {'datetime':datetime.datetime.now(),
         'date':datetime.datetime.now().date(),
         'x': Decimal('5.5')},
        cls=MyJsonEncoder)